﻿using System;
using System.Collections.Generic;
using CookComputing.XmlRpc;
//
using PerceptiveMCAPI.Types;
using PerceptiveMCAPI.Types.Internal;
//
namespace PerceptiveMCAPI.Methods
{
   public class listStaticSegmentDelMembers : Api_BaseExecute
   {
      private new listStaticSegmentDelMembersInput Input { get; set; }
      private listStaticSegmentDelMembersOutput Output { get; set; }
      // =============================================== constructors
      public listStaticSegmentDelMembers() { }
      // ---------
      public listStaticSegmentDelMembers( listStaticSegmentDelMembersInput input ) { Input = input; }
      // =============================================== Execute
      public listStaticSegmentDelMembersOutput Execute()
      {
         // empty constructor & Execute() is bad
         if ( Input == null )
            throw new ArgumentException( "Input class not provided" );
         // do the deed
         Output = Execute( Input );
         return Output;
      }
      // ---------------------------------------------
      public listStaticSegmentDelMembersOutput Execute( listStaticSegmentDelMembersInput input )
      {
         Input = input;
         Output = new listStaticSegmentDelMembersOutput( Input );
         ValidationIsOK = true;
         //-------------------------
         if ( Input.api_Validate )
         {
            Output.api_ValidatorMessages = ValidateInput.Validate( Input );
            ValidationIsOK = ValidateInput.IsOK( Output.api_ValidatorMessages );
         }
         //------------------------- do it
         if ( ValidationIsOK )
         {
            ApiRun( Input, input.parms.apikey );  // execute API & format output
         }
         // ---
         return Output;
      }

      #region ================================================================= API Calls
      // ---------------------------------------------------------- XmlRpc
      protected override void ExecuteXmlRpc()
      {
         try
         {
            string[] batch = apiHelper.MakeArrayFromList<string>( Input.parms.batch );
            x_listStaticSegmentDelMembers rpcResult = apiXmlRpc.api.listStaticSegmentDelMembers(
               Input.parms.apikey, Input.parms.id, Input.parms.seg_id, batch );
            Output.Format( rpcResult );
         }
         catch ( XmlRpcFaultException fex )
         {
            Output.api_ErrorMessages.Add( apiException.FormatError( fex ) );
         }
         catch ( Exception ex )
         {
            Output.api_ErrorMessages.Add( apiException.FormatError( ex ) );
         }

      }

      // ---------------------------------------------------------- Serial Post
      protected override void ExecuteSerialPost()
      {
         try
         {
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add( "apikey", Input.parms.apikey );
            dict.Add( "id", Input.parms.id );
            dict.Add( "seg_id", Input.parms.seg_id.ToString() );
            //
            for ( int ix = 0; ix < Input.parms.batch.Count; ix++ )
            {
               dict.Add( string.Format( "batch[{0}]", ix ), Input.parms.batch[ix] );
            }
            // -- do it
            string api_Request = "";
            string api_Response = apiSerial.ProcessRequest( Input, dict, out api_Request );
            Output.Format( api_Request, api_Response );
         }
         catch ( Exception ex )
         {
            Output.api_ErrorMessages.Add( apiException.FormatError( ex ) );
         }
      }
      #endregion


   }
}
